/**
 * @fileOverview The "format" plugin.
 */
VED.plugins.add( 'format', {
   requires: 'richcombo',
   lang: 'en,ru', // %REMOVE_LINE_CORE%
   init: function( editor ) {
      if ( editor.blockless )
         return;

      var config = editor.config,
         lang = editor.lang.format;

      // Gets the list of tags from the settings.
      var tags = config.format_tags.split( ';' );

      // Create style objects for all defined styles.
      var styles = {},
         stylesCount = 0,
         allowedContent = [];
      for ( var i = 0; i < tags.length; i++ ) {
         var tag = tags[ i ];
         var style = new VED.style( config[ 'format_' + tag ] );
         if ( !editor.filter.customConfig || editor.filter.check( style ) ) {
            stylesCount++;
            styles[ tag ] = style;
            styles[ tag ]._.enterMode = editor.config.enterMode;
            allowedContent.push( style );
         }
      }

      // Hide entire combo when all formats are rejected.
      if ( stylesCount === 0 )
         return;

      editor.ui.addRichCombo( 'Format', {
         label: lang.label,
         title: lang.panelTitle,
         toolbar: 'styles,20',
         allowedContent: allowedContent,

         panel: {
            css: [ VED.skin.getPath( 'editor' ) ].concat( config.contentsCss ),  //???????
            multiSelect: false,
            attributes: { 'aria-label': lang.panelTitle }
         },

         init: function() {
            this.startGroup( lang.panelTitle );

            for ( var tag in styles ) {
               var label = lang[ 'tag_' + tag ];

               // Add the tag entry to the panel list.
               this.add( tag, styles[ tag ].buildPreview( label ), label );
            }
         },

         onClick: function( value ) {
            editor.focus();
            editor.fire( 'saveSnapshot' );

            var style = styles[ value ],
               elementPath = editor.elementPath();

            editor[ style.checkActive( elementPath ) ? 'removeStyle' : 'applyStyle' ]( style );

            // Save the undo snapshot after all changes are affected. (#4899)
            setTimeout( function() {
               editor.fire( 'saveSnapshot' );
            }, 0 );
         },

         onRender: function() {
            editor.on( 'selectionChange', function( ev ) {

               var currentTag = this.getValue(),
                  elementPath = ev.data.path,
                  isEnabled = !editor.readOnly && elementPath.isContextFor( 'p' );

               // Disable the command when selection path is "blockless".
               this[ isEnabled ? 'enable' : 'disable' ]();

               if ( isEnabled ) {

                  for ( var tag in styles ) {
                     if ( styles[ tag ].checkActive( elementPath ) ) {
                        if ( tag != currentTag )
                           this.setValue( tag, editor.lang.format[ 'tag_' + tag ] );
                        return;
                     }
                  }

                  // If no styles match, just empty it.
                  this.setValue( '' );
               }
            }, this );
         }
      });
   }
});

VED.config.format_tags = 'p;h1;h2;h3;h4;h5;h6;pre;address';//;div';

VED.config.format_p = { element: 'p' };
// VED.config.format_div = { element: 'div' };
VED.config.format_pre = { element: 'pre' };
VED.config.format_address = { element: 'address' };
VED.config.format_h1 = { element: 'h1' };
VED.config.format_h2 = { element: 'h2' };
VED.config.format_h3 = { element: 'h3' };
VED.config.format_h4 = { element: 'h4' };
VED.config.format_h5 = { element: 'h5' };
VED.config.format_h6 = { element: 'h6' };






